package cn.tedu._04mvcweibo.interceptor;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**认证过滤器*/
public class AuthFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("AuthFilter 认证过滤器");
        HttpSession session=((HttpServletRequest)servletRequest).getSession(true);
        Object user=session.getAttribute("user");
        if(user==null)
            throw new RuntimeException("请先登录");
        //请求如何继续传递
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
